#include "..\inc\Processor.h"

Processor::Processor (void) {
}

percent Processor::compareMatrix (const IMat& first, const IMat& second, double accuracy) {
	percent result = 0;
	unsigned int columnCount = first.GetColumnCount ();
	unsigned int rowCount = first.GetRowCount ();
	if (columnCount == second.GetColumnCount () && rowCount == second.GetRowCount () && columnCount != 0 && rowCount != 0) {
		unsigned int i = 0;
		if ( columnCount > rowCount) {
			for (i = 0; i < rowCount; ++i) {
				result += compareRow (first.GetRow (i), second.GetRow (i), accuracy);
			}
		}
		else {
			for (i = 0; i < columnCount; ++i) {
				result += compareColumn (first.GetColumn (i), second.GetColumn (i), accuracy);
			}
		}
		result = result / (percent) i;
	}
	return (result);
}

percent Processor::compareRow (const MatrixRow& first, const MatrixRow& second, double accuracy) {
	percent result = 0;
	unsigned int rowSize = first.size ();
	if (rowSize == second.size () && rowSize != 0) {
		int countOfEquals = 0;
		for (unsigned int i = 0; i < rowSize; ++i) {
			if (abs (first[i] - second[i]) <= abs (accuracy)) {
				countOfEquals ++;
			}
		}
		result = ((double) countOfEquals / (double) rowSize) * 100.0;
	}
	return (result);
}

percent Processor::compareColumn (const MatrixColumn& first, const MatrixColumn& second, double accuracy) {
	percent result = compareRow (first, second, accuracy);
	return (result);
}